<!doctype html>
<html lang="en">
  <head>
    <title>林科大校医</title>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  </head>
  <body>
<div id="app">
    <nav class="navbar navbar-expand-md  navbar-dark" style="background-color: #0991f3;">
        <a class="navbar-brand" href="#">林科大校医 🏥 </a>
        <div class="collapse navbar-collapse" id="collapsibleNavId">
            <!-- 在这个导航栏中定义每一个选项 -->
            <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
                <!-- 一个选项就是一个li标签 -->
                <li class="nav-item active ml-3">
                    <a class="nav-link" href="#">首页<span class="sr-only">(current)</span></a>
                </li>
                <li class="nav-item ml-3">
                    <a class="nav-link" href="#">文件</a>
                </li>
                <!-- 有下拉选项的li标签 -->
                <li class="nav-item dropdown ml-3">
                    <a class="nav-link dropdown-toggle" href="#" id="dropdownId" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">编辑</a>
                   <!-- 下拉选项的值 -->
                    <div class="dropdown-menu" aria-labelledby="dropdownId">
                        <a class="dropdown-item" href="#">撤销</a>
                        <a class="dropdown-item" href="#">恢复</a>
                        <a class="dropdown-item" href="#">剪切</a>
                        <a class="dropdown-item" href="#">复制</a>
                    </div>
                </li>
                <li class="nav-item dropdown ml-3">
                    <a class="nav-link dropdown-toggle" href="#" id="dropdownId" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">选择</a>
                   <!-- 下拉选项的值 -->
                    <div class="dropdown-menu" aria-labelledby="dropdownId">
                        <a class="dropdown-item" href="#">撤销</a>
                        <a class="dropdown-item" href="#">恢复</a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" href="#">剪切</a>
                        <a class="dropdown-item" href="#">复制</a>
                    </div>
                </li>
            </ul>
            <form class="form-inline my-2 my-lg-0">
                <input class="form-control mr-sm-2" type="text" placeholder="Search">
                <button class="btn btn-danger my-2 my-sm-0" type="submit">Search</button>
            </form>
        </div>
    </nav>
    <!-- 组件2：展板 b4-jum -->
    <div class="jumbotron jumbotron-fluid py-3">
        <div class="container">
            <!-- dispaly-1/5:表示字体大小 -->
            <h1 class="display-4">线上挂号系统</h1>
            <p class="lead">林科大校医</p>
        </div>
            <!-- 可以添加其他的内容包括组件  面包屑导航  b4-bread -->
        <nav class="breadcrumb">
            <a class="breadcrumb-item" href="index.html">科室导航</a>
            <a class="breadcrumb-item" href="departscheduling.html" v-if="depart!=null">{{depart.title}}排班</a>
            <a class="breadcrumb-item" href="index.html" v-else>请选择科室</a>
            <span class="breadcrumb-item active">就诊人管理</span>
            <a class="breadcrumb-item" href="reservationinfo.html">我的预约信息</a>
        </nav>
    </div>

    <!-- 就诊人信息 -->
    <div class="container">
        <h1 class="font-weight-light h2 mb-4 offset-1">就诊人管理</h1>
        <!-- 首行，显示一个按钮 -->
        <div class="row mb-3">
            <div class="offset-1 col-md-2">
                <button class="btn btn-success" data-toggle="modal" data-target="#modelId">新增就诊人</button>
            </div>
            <div class="offset-1 col-md-2">
                <button class="btn btn-danger" data-toggle="modal" data-target="#modelId">删除选中项</button>
            </div>
        </div>

        <!--添加就诊人 模态框 -->
        <!-- Modal -->
        <div class="modal fade" id="modelId" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                        <div class="modal-header">
                                <h5 class="modal-title">就诊人添加</h5>
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
                        </div>
                    <div class="modal-body">
                        <div class="container-fluid">
                            <!-- 身体部分 需要添加的数据-->
                            <!-- b4-input-text  文本框  -->
                            <div class="form-group row">
                              <label for="name" class="col-sm-3 mt-2">姓名</label>
                              <input type="text" v-model="newpatient.name" class="col-sm-9 form-control" name="name" id="name" aria-describedby="helpId" placeholder="请输入姓名">
                            </div>
                            <div class="form-group row">
                                <label for="cardId" class="col-sm-3 mt-2">身份证</label>
                                <input type="text" v-model="newpatient.idCard" class="col-sm-9 form-control" name="cardId" id="cardId" aria-describedby="helpId" placeholder="请输入身份证">
                              </div>
                              <div class="form-group row">
                                <label for="tel" class="col-sm-3 mt-2">手机</label>
                                <input type="text" v-model="newpatient.phone" class="col-sm-9 form-control" name="tel" id="tel" aria-describedby="helpId" placeholder="请输入手机号">
                              </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" @click="addPatient()" data-dismiss="modal">添加</button>
                    </div>
                </div>
            </div>
        </div>
     

        <!-- 模态框：修改就诊人信息 -->
        <div class="modal fade" id="modelEdit" tabindex="-1" role="dialog" aria-labelledby="modelTitleId" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                        <div class="modal-header">
                                <h5 class="modal-title">就诊人修改</h5>
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
                        </div>
                    <div class="modal-body">
                        <div class="container-fluid">
                            <!-- 身体部分 需要添加的数据-->
                            <!-- b4-input-text  文本框  -->
                            <div class="form-group row">
                              <label for="name" class="col-sm-3 mt-2">姓名</label>
                              <input type="text" v-model="editpatient.name" class="col-sm-9 form-control" name="name" id="name" aria-describedby="helpId" placeholder="请输入姓名">
                            </div>
                            <div class="form-group row">
                                <label for="cardId" class="col-sm-3 mt-2">身份证</label>
                                <input type="text" v-model="editpatient.idCard" class="col-sm-9 form-control" name="cardId" id="cardId" aria-describedby="helpId" placeholder="请输入身份证">
                              </div>
                              <div class="form-group row">
                                <label for="tel" class="col-sm-3 mt-2">手机</label>
                                <input type="text" v-model="editpatient.phone" class="col-sm-9 form-control" name="tel" id="tel" aria-describedby="helpId" placeholder="请输入手机号">
                              </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" @click="updatePatient()" data-dismiss="modal">添加</button>
                    </div>
                </div>
            </div>
        </div>
        <!-- 第二行显示一个表格 -->
        <div class="row">
            <table class="table table-striped table-hover offset-1 col-md-10">
                <thead>
                    <tr>
                        <th>
                            <input type="checkbox" class="main_check_item" @click="selectAll()" v-model="isAllSelect" id="main_check_item"/>
                            选择
                        </th>
                        <th>姓名</th>
                        <th>身份证号</th>
                        <th>手机号</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                   <tr v-for="(patient, index) in patientArr" :key="index">
                       <td>
                               <input type="checkbox" class="check_item"/>
                       </td>
                       <td>{{patient.name}}</td>
                       <td>{{patient.idCard}}</td>
                       <td>{{patient.phone}}</td>
                       <td>
                           <button class="btn btn-warning" @click="edit(patient)"  data-toggle="modal" data-target="#modelEdit">编辑</button>
                           <button class="btn btn-danger" @click="del(patient.id, patient.name)">删除</button>
                       </td>
                   </tr>
                  
                </tbody>
            </table>
        </div>
    </div>
     <!-- 页脚&网址地图 -->
     <div class="jumbotron jumbotron-fluid mb-0 mt-5 py-3">
        <div class="container">
            <p class="lead text-center">copyright 牛耳教育@2022</p>
        </div>
    </div>
</div>
    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script> 
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  </body>
</html>
<script>
    var url = `http://localhost:8080`;
    new Vue({
        el:"#app", 
        data() {
            return {
                patientArr:[],
                editpatient:{},
                newpatient:{},
                depart:null,
                delArr:[],
                isAllSelect:false
            }
        },
        mounted() {
            this.getallPatient();
            this.depart = JSON.parse(sessionStorage.getItem("curDepart"));
        },
        methods: {
            getallPatient(){
                axios.get(`${url}/manager/selectAllPatient`)
                .then( (response) =>{
                    this.patientArr = response.data;
                })
                .catch(function (error) {
                })
            },
            addPatient(){
                axios.post(`${url}/manager/add`, this.newpatient)
                .then( (response) =>{
                   let flag = response.data;
                   if(flag){
                        alert("添加成功！");
                        this.getallPatient();
                   }
                })
                .catch(function (error) {
                })
            },
            updatePatient() {
                axios.put(`${url}/manager/update`,this.editpatient)
                .then( (response)=> {
                    if(response.data){
                        alert("修改成功！");
                        this.getallPatient();
                    }else{
                        alert("修改失败！");
                    }
                })
                .catch(function (error) {
                })
            },
            edit(patient){
               this.editpatient = {
                   id:patient.id,
                   name:patient.name,
                   phone:patient.phone,
                   state:patient.state,
                   idCard:patient.idCard
               }
               console.log(this.editpatient);
            },
            //单次删除
            del(id,name){
                if(confirm("是否确定删除【"+name+"】这个就诊人！")){
                    axios.put(`${url}/manager/del/${id}`)
                    .then( (response) =>{
                        if(response.data){
                            alert("删除成功！");
                            this.getallPatient();
                        }else{
                            alert("删除失败");
                        }
                    })
                    .catch(function (error) {
                    })
                }
                
            },
            //批量删除
            delAll(){

            },
            selectAll(){
                this.isAllSelect = !this.isAllSelect;
                if(this.isAllSelect){
                    document.getElementById("main_check_item").setAttribute('checked','checked');
                    var elementsByClassName = document.getElementsByClassName("check_item");
                    for (const elementsByClassNameElement of elementsByClassName) {
                        elementsByClassNameElement.checked = true;
                    }
                }else{
                    var elementsByClassName = document.getElementsByClassName("check_item");
                    for (const elementsByClassNameElement of elementsByClassName) {
                        elementsByClassNameElement.checked = false;
                    }
                }
            },
            searchListener(){//本搜索的实质是过滤 --2022/7/7--zxj
                let input = document.getElementById("search").value;
                let reg = new RegExp(input+".*");
                this.patientArr = this.patientArr.filter(item=>{return reg.test(item.name)==true});
            },

            removeAll(){//本删除的实质是隐藏 --2022/7/8 --zxj
                if(confirm("are you sure?")){
                    this.patientArr.splice(0,this.patientArr.length);
                }
            }

        },
    })
</script>